package furnitureBuilder;
import builderObserver.Observer;
import createdFurnituries.RoomList;

import java.util.ArrayList;
import java.util.List;
/**
 * 
 * @author dbatir
 *
 */
public class BedroomBuilder {
	List<Observer> observers = new ArrayList<Observer>();
	/**
	 * build Cherry lumber type room
	 * @return
	 */
	public Bedroom buildCherryRoom() {
		Bedroom room = new Bedroom();
		room.addItem(new CherryBedside());
		room.addItem(new CherryChest());
		room.addItem(new CherryBed());
		room.setBeedroomLumberType("Cherry");
		RoomList.addRoomWithType(room);
		notifyAllObservers(room);
		return room;
	}
	
	/**
	 * build Oak lumber type room
	 * @return
	 */
	public Bedroom buildOakRoom() {
		Bedroom room = new Bedroom();
		room.addItem(new OakBed());
		room.addItem(new OakBedside());
		room.addItem(new OakChest());
		room.setBeedroomLumberType("Oak");
		RoomList.addRoomWithType(room);
		notifyAllObservers(room);
		return room;
	}
	
	/**
	 * build mixed lumber type room
	 * @return
	 */
	public Bedroom buildMixedRoom() {
		Bedroom room = new Bedroom();
		room.addItem(new OakBed());
		room.addItem(new CherryChest());
		room.addItem(new CherryBedside());
		room.setBeedroomLumberType("Mixed");
		RoomList.addRoomWithType(room);
		notifyAllObservers(room);
		return room;
	}
	
	/**
	 * Attach observer to builder
	 * @param observer
	 */
	public void attachObserver(Observer observer) {
		observers.add(observer);
	}
	
	/**
	 * The method notify observer when room is created
	 * @param room
	 */
	public void notifyAllObservers(Bedroom room) {
		RoomList.rooms.add(room);
		for(Observer obj : observers) {
			obj.saveToFile(room);
		}
		
	}
}
